#pragma once
#include "afxwin.h"
#include "WeaponDlg.h"
#include "ItemsDlg.h"
#include "AttachDefs.h"


using namespace std;
// CAttachDlg dialog
#define ATTACH_LOAD   "\\attach.ini"
#define ATTACH_SAVE   "\\attach.ini"

class CAttachDlg : public CDialog
{
	DECLARE_DYNAMIC(CAttachDlg)

public:
	CAttachDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CAttachDlg();

// Dialog Data
	enum { IDD = IDD_ATTACH };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
private:
  bool m_bSaved;
  COXToolTipCtrl m_tooltip;
public:
  bool IsSaved() const { return m_bSaved; };
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	void OnOK();
	void OnCancel();
	CListBox m_lbAttInfo;
	CListBox m_lbAttach;
	CListBox m_lbLaunchable;
	CListBox m_lbFaceCombo;
	CListBox m_lbMerge;
	CListBox m_lbCombo;
	CComboBox m_cbItemClass;
	CComboBox m_cbSkillCheck;
	afx_msg void OnLbnSelchangeListAttachmentInfo();
	afx_msg void OnLbnSelchangeListAttaches();
	afx_msg void OnLbnSelchangeListLaunchable();
	afx_msg void OnLbnSelchangeListFaceCombo();
	afx_msg void OnLbnSelchangeListMerge();
	afx_msg void OnLbnSelchangeListCombo();
	afx_msg void OnCbnSelchangeComboAttachmentInfoItemClass();
	afx_msg void OnCbnSelchangeComboAttachmentInfoSkillCheck();
	afx_msg void OnCbnSelchangeComboMergeMergeResult();
	afx_msg void OnEnChangeEdit1();
	afx_msg void OnEnChangeEditAttachmentInfoSkillCheckModifier();
	afx_msg void OnEnChangeEdit3();
	afx_msg void OnEnChangeEdit4();

	AttachmentInfoStruct AttachmentInfo[MAX_ATTACHMENTINFO];
  int AttachInfoNStart, AttachInfoNFinish;
  int m_icsAI;
  void ChangeAI();
  void FillAI();

  UINT16 Attachment[MAX_ATTACH][2];
  int AttachmentNStart, AttachmentNFinish;
  int m_icsAtt;
  void ChangeATT();
  void FillAtt();

  UINT16 Launchable[MAX_LAUNCHABLE][2];
  int LaunchableNStart, LaunchableNFinish;
  int m_icsL;
  void ChangeL();
  void FillLaun();

  UINT16 CompatibleFaceItems[MAX_FACECOMBO][2];
  int CompatibleFaceItemsNStart, CompatibleFaceItemsNFinish;
  int m_icsFC;
  void ChangeFC();
  void FillFC();

  UINT16 Merge[MAX_MERGE][4];
  int MergeNStart, MergeNFinish;
  int m_icsM;
  void ChangeM();
  void FillMerge();
  
  ComboMergeInfoStruct AttachmentComboMerge[MAX_COMBO];
  int AttachmentComboMergeNStart, AttachmentComboMergeNFinish;
  int m_icsC;
  void ChangeC();
  void FillCombo();

  UINT16 GetMergeMethodByName(LPCTSTR tsClass);
	char* GetMergeMethodNameByID(UINT ID);

	int GetSkillCheckIdByName(LPCTSTR tsClass);
	char *GetSkillChekNameByID(UINT ID);

	void Load( CProgressBarDialog *pProgressDialog );
	void Save();

	void GetAttachsIniSettings( CProgressBarDialog *pProgressDialog );
  void SetClassPointers(ClassPointers *p);

	void FillIC();
	void FillMergeType();
	void FillSkCheck();

  void sortMerge(int idx = -1, int cnt = -1 );
  void sortLaun(int idx = -1, int cnt = -1 );
  void sortAtt(int idx = -1, int cnt = -1 );
  void sortFC(int idx = -1, int cnt = -1 );
  void sortC(int idx = -1, int cnt = -1 );

	CComboBox m_cbMergeType;
	CComboBox m_cbAttachAttach;
	CComboBox m_cbAttachTo;
  CComboBox m_cbAttachInfoItem;

  CWeaponDlg *pWeapDlg;
  CWeapTTX   *pWeapTTX;
  CItemsDlg  *pItemDlg;

  CComboBox m_cbLaunchableAmmo;
  CComboBox m_cbLaunchableWeapon;
  CComboBox m_cbMergeAttach;
  CComboBox m_cbMergeItem;
  CComboBox m_cbMergeResult;
  CComboBox m_cbComboItem;
  CComboBox m_cbComboResult;
  CComboBox m_cbComboAtt1;
  CComboBox m_cbComboAtt2;
  CComboBox m_cbFaceComboI1;
  CComboBox m_cbFaceComboI2;
  afx_msg void OnCbnSelchangeComboLaunchableAmmo();
  afx_msg void OnCbnSelchangeComboLaunchableWeapon();
  afx_msg void OnCbnSelchangeComboAttachmentInfoItem();
  afx_msg void OnCbnSelchangeComboMergeAttach();
  afx_msg void OnCbnSelchangeComboMergeItem();
  afx_msg void OnCbnSelchangeComboMergeResult();
  afx_msg void OnCbnSelchangeComboFaceComboItem1();
  afx_msg void OnCbnSelchangeComboFaceComboItem2();
  afx_msg void OnCbnSelchangeComboComboItem();
  afx_msg void OnCbnSelchangeComboComboAttach1();
  afx_msg void OnCbnSelchangeComboComboAttach2();
  afx_msg void OnCbnSelchangeComboComboResult();
  afx_msg void OnCbnSelchangeAttachAttach();
  afx_msg void OnCbnSelchangeAttachTo();

  BOOL PreTranslateMessage(MSG* pMsg) 
  {
    if(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST)
      m_tooltip.RelayEvent(pMsg);

    return CDialog::PreTranslateMessage(pMsg);
  }
};
